package com.cuijq.ms.shopping;

import java.util.ArrayList;
import java.util.List;

/**
 * 滥用 getter setter
 * 明显违反了面向对象的封装特性
 * 而面向对象封装的定义是：通过访问权限控制，隐藏内部数据，外部仅能通过类提供的有限的接口访问、修改内部数据
 */
public class ShoppingCart {
    private int itemsCount;
    private double totalPrice;
    private List items = new ArrayList<>();

    public int getItemsCount() {
        return this.itemsCount;
    }

    public void setItemsCount(int itemsCount) {
        this.itemsCount = itemsCount;
    }

    public double getTotalPrice() {
        return this.totalPrice;
    }

    public void setTotalPrice(double totalPrice) {
        this.totalPrice = totalPrice;
    }

    public List getItems() {
        return this.items;
    }

    public void addItem(ShoppingCartItem item) {
        items.add(item);
        itemsCount++;
        totalPrice += item.getPrice();
    } // ...省略其他方法...}

    public void clear() {
        items.clear();
        itemsCount = 0;
        totalPrice = 0.0;
    }
}
